package cn.jbolt.ec.member;

import cn.jbolt.base.JBoltBaseService;
import cn.jbolt.common.model.BecMemberAddress;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Kv;

import java.util.List;

/**
 * @author xieguo
 * @description 会员地址业务逻辑层
 */
public class AddressService extends JBoltBaseService<BecMemberAddress> {
    private BecMemberAddress dao = new BecMemberAddress().dao();
    @Override
    protected BecMemberAddress dao() {
        return dao;
    }
    @Inject
    MemberService memberService;

    /**
     * 会员地址信息
     * @param memberid
     * @return
     */
    public List<BecMemberAddress> get_member_address_info(Integer memberid){
        Kv param=Kv.by("memberid",memberid);
        return getCommonList("id,memberid,adress,adress_detail,mobile,consignee,is_major,province,city,area",param);
    }

    /**
     * 保存会员地址
     * @param adress
     * @param adress_detail
     * @param mobile
     * @param consignee
     * @param is_major
     * @param province
     * @param city
     * @param area
     * @return
     */
    public boolean address_append(Integer memberid,String adress,String adress_detail,String mobile,String consignee,Integer is_major,String province,String city,String area){
        boolean major=is_major!=0?true:false;
        if (major){
            Kv param=Kv.by("memberid",memberid);
            dbTemplate("ec.mall.shop.member.insert_member_address",param).update();
        }
        BecMemberAddress becMemberAddress=new BecMemberAddress();
        becMemberAddress.set("memberid",memberid).set("adress",adress).set("adress_detail",adress_detail).set("mobile",mobile)
                .set("consignee",consignee).set("is_major",major).set("province",province).set("city",city).set("area",area);
        return becMemberAddress.save();
    }

    /**
     * 更新会员地址
     * @param id
     * @param adress
     * @param adress_detail
     * @param mobile
     * @param consignee
     * @param is_major
     * @param province
     * @param city
     * @param area
     * @return
     */
    public boolean address_modify(Integer id,Integer memberid,String adress,String adress_detail,String mobile,String consignee,Integer is_major,String province,String city,String area){
        boolean major=is_major!=0?true:false;
        if (major){
            Kv param=Kv.by("memberid",memberid);
            dbTemplate("ec.mall.shop.member.insert_member_address",param).update();
        }
        BecMemberAddress becMemberAddress=new BecMemberAddress().dao().findById(id);
        becMemberAddress.set("adress",adress).set("adress_detail",adress_detail).set("mobile",mobile).set("consignee",consignee).set("is_major",major).set("province",province).set("city",city).set("area",area);
        return becMemberAddress.update();
    }

    /**
     * 删除会员地址
     * @param id
     * @return
     */
    public boolean address_delete(Integer id){
        return new BecMemberAddress().dao().deleteById(id);
    }
}
